const action = require('../action');
const apiPrefix = require('../config').apiPrefix;
const APIError = require('../module/rest').APIError;

module.exports = {
    'GET /api/result-list': async (ctx, next) => {

        let returnData = await action.result.getByTableId(ctx.request.query.tableId);
        if (returnData.result) {
            ctx.rest({
                "result": returnData.data
            });
        } else {
            throw new APIError("result:not_found", "result not found by tableId.");
        }
    },

    'POST /api/result': async (ctx, next) => {
        let returnData = await action.result.create(ctx.request.body.result);
        if (returnData.result) {
            ctx.rest({
                "result": returnData.data
            });
        } else {
            throw new APIError("result:create_failed", "result table failed");
        }
    },

};